//
//  JKLogManager.m
//  RunloopTableViewDemo
//
//  Created by Jack on 2021/6/30.
//

#import "JKLogManager.h"

@implementation JKLogManager{
    NSMutableArray *_dataArray;
}

+ (instancetype)sharedManager{
    static JKLogManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[JKLogManager alloc] init];
    });
    return manager;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _dataArray = [[NSMutableArray alloc] initWithCapacity:0];
        _logView = [[JKLogView alloc] initWithFrame:CGRectZero];
    }
    return self;
}

#pragma mark - Public
- (void)addLog:(NSString *)log{
    if (!log || ![log isKindOfClass:[NSString class]] || log.length == 0) {
        return;
    }
    [_dataArray addObject:log];
    if (!CGRectEqualToRect(_logView.frame, CGRectZero)) {
        //logView已经展示
        [_logView addLogToView:log];
    }
}

- (NSArray *)allLogs{
    return _dataArray;
}

@end
